package com.ymatou.iapi.ocr.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.ocr.parameter.DoImMessageOcrBean;
import com.ymatou.iapi.ocr.service.DoImMessageOcrCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.OCRWrapper;

/**
 * 批量扫描im历史图片 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DoImMessageOcr {
	private static DoImMessageOcrBean doimmessageocrBean;
	private static DoImMessageOcrCall doimmessageocrCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量扫描im历史图片");
	}

	@Before
	public void caseUp() {
		doimmessageocrBean = new DoImMessageOcrBean();
		doimmessageocrCall = new DoImMessageOcrCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(doimmessageocrCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	// job需要手动验证
	public void Tc_DoImMessageOcr_001() {
		Logger.start(true, "批量扫描im历史图片");
		try {
			OCRWrapper test = new OCRWrapper();
			int last = 0;
			for (int index = 0; index < 64; index++) {
				for (int i = 0; i < 10000; i++) {
					Logger.debug("开始：" + i);
					doimmessageocrBean.setBatchSize(1000);
					doimmessageocrBean.setTableIndex(index);
					doimmessageocrCall.setData(doimmessageocrBean);
					doimmessageocrCall.callService();
					Logger.verifyEquals("ok", doimmessageocrCall.getReturnData(), "返回ok");
					Thread.sleep(100);
					Map map = test.selectTopicWeixinJobByTablename(doimmessageocrBean.getTableIndex()).get(0);
					while (!map.get("SyncStatus").toString().equals("0")) {
						Logger.debug("未处理完成：" + map.get("SyncStatus"));
						Logger.debug(map);
						Thread.sleep(1000);
						map = test.selectTopicWeixinJobByTablename(doimmessageocrBean.getTableIndex()).get(0);
					}
					Logger.debug(last + ":" + map.get("LastSyncIndex"));
					if (last != Integer.valueOf(map.get("LastSyncIndex").toString())) {
						last = Integer.valueOf(map.get("LastSyncIndex").toString());
					} else {
						Logger.debug(index + ":同步结束");
						break;
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}